<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <title>忘记密码</title>
    <link href="global/css/login.css" type="text/css" rel="stylesheet">
</head>
<body>

<div class="login">
    <div class="message">后台管理系统</div>
    <div id="darkbannerwrap"></div>

    <form id="login-form" method="post" onsubmit="return false;">
        <input id="phone" name="phone" placeholder="手机号" type="text"
               autocomplete="off">
        <hr class="hr15">
        <input id="code" name="code" placeholder="验证码" type="text"
               autocomplete="off">
       <input id="password" name="password" placeholder="密码" type="password"
               autocomplete="off"
               data-bv-notempty="true"
               data-bv-notempty-message="新密码不能为空"
               data-bv-identical="true"
               data-bv-identical-field="newpwd"
               data-bv-identical-message="两次密码不一致">
       <input class="form-control" placeholder="再次输入新密码" type="password" name="newpwd" id="newpwd"
               autocomplete="off"
               data-bv-notempty="true"
               data-bv-notempty-message="再次输入新密码"
               data-bv-identical="true"
               data-bv-identical-field="password"
               data-bv-identical-message="两次密码不一致">

        <!--<div class="form-group">
            <label class="col-md-2 control-label">新密码</label>
            <div class="col-md-10">
                <input class="form-control" placeholder="新密码" type="password" name="password" id="password"
                       data-bv-notempty="true"
                       data-bv-notempty-message="新密码 不能为空"

                       data-bv-identical="true"
                       data-bv-identical-field="newpwd"
                       data-bv-identical-message="两次密码不一致">
            </div>
        </div>
        <div class="form-group">
            <label class="col-md-2 control-label">再次输入新密码</label>
            <div class="col-md-10">
                <input class="form-control" placeholder="再次输入新密码" type="password" name="newpwd" id="newpwd"
                       data-bv-notempty="true"
                       data-bv-notempty-message="再次输入新密码"
                       data-bv-identical="true"
                       data-bv-identical-field="password"
                       data-bv-identical-message="两次密码不一致">
            </div>
        </div>-->


        <button class="layui-btn layui-btn-sm" onclick="location.href='/login.html'">
            返回登录
        </button>
        <hr class="hr15">
        <button style="width: 100%;" type="submit"
                onclick="add()">提交
        </button>
        <hr class="hr20">
        <span id="info" style="color: red"></span>
    </form>


</div>

</body>
<script src="global/js/libs/jquery-2.1.1.min.js"></script>
<script type="text/javascript">
    if (top != self) {
        parent.location.href = '/login.html';
    }

    var token = localStorage.getItem("token");
    if (token != null && token.trim().length != 0) {
        $.ajax({
            type: 'get',
            url: '/users/current?token=' + token,
            success: function (data) {
                location.href = '/index.html';
            },
            error: function (xhr, textStatus, errorThrown) {
                var msg = xhr.responseText;
                var response = JSON.parse(msg);
                var code = response.code;
                var message = response.message;
                if (code == 401) {
                    localStorage.removeItem("token");
                }
            }
        });
    }

    function add() {
        var p = $("#phone").val();
        var c = $("#code").val();
        var d = $("#password").val();
        var n = $("#newpwd").val();

        $.ajax({
            data: {
                phone: p,
                code: c,
                password: d,
                newpwd: n,
            },
            dataType: 'json',
            type: 'post',
            url: '/clyjUser/updatepwd',
            async: true,
            success: function (date) {
                var phone = data.phone;
                if (phone == "success") {
                    layer.msg("手机号正确")
                }
                if (password == "success") {
                    layer.msg("密码修改成功正确")
                }
            }
        });
    }

    function login(obj) {
        $(obj).attr("disabled", true);

        var username = $.trim($('#username').val());
        var password = $.trim($('#password').val());
        if (username == "" || password == "") {
            $("#info").html('用户名或者密码不能为空');
            $(obj).attr("disabled", false);
        } else {
            $.ajax({
                type: 'post',
                url: '/login',
                data: $("#login-form").serialize(),
                success: function (data) {
                    localStorage.setItem("token", data.token);
                    location.href = '/index.html';
                },
                error: function (xhr, textStatus, errorThrown) {
                    var msg = xhr.responseText;
                    var response = JSON.parse(msg);
                    $("#info").html(response.message);
                    $(obj).attr("disabled", false);
                }
            });

        }
    }
</script>
</html>